﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using System.Collections;

namespace CRM_SMS_MARKETING
{
    public partial class RibbonForm2 : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public RibbonForm2()
        {
            InitializeComponent();
        }

        private void gridView1_DragObjectStart(object sender, DevExpress.XtraGrid.Views.Base.DragObjectStartEventArgs e)
        {
            int[] rows = gridView1.GetSelectedRows();
            List<DataRow> list = new List<DataRow>();
            foreach (var index in rows)
            {
                DataRow r = (this.gridControl1.DataSource as DataTable).NewRow();
                DataRow row = (this.gridControl1.DataSource as DataTable).Rows[index];
                r.ItemArray = row.ItemArray;
                list.Add(r);
            }

            // e.DragObject = list;
        }



        private void RibbonForm2_Load(object sender, EventArgs e)
        {
            DataTable t1 = new DataTable();
            t1.Columns.Add(new DataColumn("id", typeof(int)));
            t1.Columns.Add(new DataColumn("name", typeof(string)));
            gridControl1.DataSource = t1;
        }

        GridHitInfo downHitInfo = null;

        private void gridView1_MouseDown(object sender, MouseEventArgs e)
        {
            GridView view = sender as GridView;

            downHitInfo = null;

            GridHitInfo hitInfo = view.CalcHitInfo(new Point(e.X, e.Y));

            if (Control.ModifierKeys != Keys.None) return;

            if (e.Button == MouseButtons.Left && hitInfo.RowHandle >= 0)

                downHitInfo = hitInfo;
        }

        private void gridView1_MouseMove(object sender, MouseEventArgs e)
        {
            GridView view = sender as GridView;

            if (e.Button == MouseButtons.Left && downHitInfo != null)
            {

                Size dragSize = SystemInformation.DragSize;

                Rectangle dragRect = new Rectangle(new Point(downHitInfo.HitPoint.X - dragSize.Width / 2,

                    downHitInfo.HitPoint.Y - dragSize.Height / 2), dragSize);



                if (!dragRect.Contains(new Point(e.X, e.Y)))
                {

                    DataRow row = view.GetDataRow(downHitInfo.RowHandle);

                    view.GridControl.DoDragDrop(row, DragDropEffects.Move);

                    downHitInfo = null;

                    DevExpress.Utils.DXMouseEventArgs.GetMouseArgs(e).Handled = true;



                }
            }
        }

        private void gridControl1_DragOver(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(DataRow)))

                e.Effect = DragDropEffects.Move;

            else

                e.Effect = DragDropEffects.None;
        }


    }

}